﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Text;
using System.Windows.Forms;

using Core.Mapping;
using Core.Graphics;
using SerializationUtilities;
using WorldEditor.Import.FromImage;
using WorldEditor.Tiles;
using Core.Graphics.Tiles;
using Core.Graphics.Layers;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace WorldEditor.MapEditor
{
    public partial class MapEditorChildForm : Form
    {
        public GraphicsDevice Graphics { get { return mapEditor1.GraphicsDevice; } }
        //Actual Map Viewer
        MapEditing mapEditor1;

        public MapEditorChildForm()
        {
            InitializeComponent();
            
            //Create MapEditor, and pass in The World
            mapEditor1 = new MapEditing();
            scMapEditor.Panel1.Controls.Add(mapEditor1); //Add Map Editor To Tab Page
            mapEditor1.Dock = DockStyle.Fill; //Set Doc to Fill so that it takes up whole page, even if we resize window.

            mapEditor1.HoverCoordinateChanged += new EventHandler(mapEditor1_HoverCoordinateChanged);
            //Set DrawArea
            mapEditor1.UpdateDrawingArea();
        }

        protected void mapEditor1_HoverCoordinateChanged(object sender, EventArgs e)
        {
            Point gp = (Point)sender;
            ////Show Current World Coordinate in StatusBar, also put it into the GoTo textbox
            //tsWorldCoordinates.Text = gp.X.ToString() + " X " + gp.Y.ToString();
            //txtGoTo.Text = gp.X.ToString() + " X " + gp.Y.ToString();
        }

        private void MapEditorChildForm_KeyDown(object sender, KeyEventArgs e)
        {
            if (mapEditor1 != null)
                mapEditor1.BasePanel.OnKeyDown(e);
        }

        private void MapEditorChildForm_KeyUp(object sender, KeyEventArgs e)
        {
            if (mapEditor1 != null)
                mapEditor1.BasePanel.OnKeyUp(e);
        }

        private void tilePallets1_Load(object sender, EventArgs e)
        {
            //auto update tile set list on load
            tilePallets1.UpdateTileSetList();
        }

        private void tilePallets1_SelectedTileChanged(object sender, EventArgs e)
        {
            //on selected tile changed, set primary on map editor
            mapEditor1.PrimaryTile = (TileSetTile)sender;
        }

        private void mapLayers1_SelectedLayerChanged(object sender, EventArgs e)
        {
            MapLayerTypes tmlt = (MapLayerTypes)sender;

            mapEditor1.CurrentLayerType = tmlt;
        }
    }
}
